<?php
class fragen_model extends CI_Model {

	public function __construct()
	{
		$this->load->database();
	}
	
	public function get_fragen()
	{
		$query = $this->db->get('fragen');
		return $query->result_array();				
	}
	
	public function get_fragen_id($fragenid)
	{
		#$this -> db -> select('ID','Beschreibung','Fach');
   		$this -> db -> from('fragen');
		$this -> db -> where('ID', $fragenid);
		
		$query = $this -> db -> get();
		
		return $query->row_array();
	}
	
	public function get_klausurfragen($klausurfragen)
	{
		foreach($klausurfragen as $frage)
		{
			$this -> db -> from('fragen');
			$this -> db -> where('ID', $frage['FragenID']);
			$query = $this -> db -> get();			
		}
		return $query->result_array(); 
	}
	
	public function set_fragen()
	{
		$this->load->helper('url');

		$ID = url_title($this->input->post('Beschreibung'), 'dash', TRUE);
		
		$data = array(
			'Fragenart' => $this->input->post('Fragenart'),
			'ID' => $ID,
			'Frage' => $this->input->post('Frage'),
			'Antwort1' => $this->input->post('Antwort1'),
			'Antwort2' => $this->input->post('Antwort2'),
			'Antwort3' => $this->input->post('Antwort3'),
			'Antwort4' => $this->input->post('Antwort4'),
			'Antwort5' => $this->input->post('Antwort5'),
			'Loesung1' => $this->input->post('Loesung1'),
			'Loesung2' => $this->input->post('Loesung2'),
			'Loesung3' => $this->input->post('Loesung3'),
			'Punkte' => $this->input->post('Punkte')
		);
		return $this->db->insert('fragen', $data);
	}
	
	public function validate_fragen($fragenid)
	{
		$this->load->helper('url');
		
		#$ID = url_title($this->input->post('Beschreibung'), 'dash', TRUE);

		$data = array(
			'Fragenart' => $this->input->post('Fragenart'),
			'Frage' => $this->input->post('Frage'),
			'Antwort1' => $this->input->post('Antwort1'),
			'Antwort2' => $this->input->post('Antwort2'),
			'Antwort3' => $this->input->post('Antwort3'),
			'Antwort4' => $this->input->post('Antwort4'),
			'Antwort5' => $this->input->post('Antwort5'),
			'Loesung1' => $this->input->post('Loesung1'),
			'Loesung2' => $this->input->post('Loesung2'),
			'Loesung3' => $this->input->post('Loesung3'),
			'Punkte' => $this->input->post('Punkte')
		);

		$where = array('ID' => $fragenid);
		return  $this->db->update('fragen',$data,$where);
	}
	
	public function get_all($limit,$offset)
	{
		$this->db->limit($limit,$offset);
		$query = $this->db->get('fragen');
		return $query->result_array();
	}

	public function get_count()
	{
		return $this->db->count_all_results('fragen');
	}
}
?>